﻿global using Devonline.AspNetCore;
global using Devonline.Core;
global using Devonline.Entity;
global using Devonline.Identity.Admin.Models;
global using static Devonline.Core.AppSettings;
using Devonline.AspNetCore.OData;
using Devonline.CloudService.Aliyun;
using Devonline.CloudService.Tencent;
using Devonline.Communication.Messages;
using Devonline.Identity;
using Devonline.Identity.Admin;
using Devonline.Logging;
using OfficeOpenXml;

ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

var builder = WebApplication.CreateBuilder(args);
builder.Host.AddLogging();
builder.AddCommunicator();
var services = builder.Services;
var appSetting = builder.AddSetting<AdminSetting>();
var mvcBuilder = services.AddIdentityControllersWithViews(appSetting).AddDefaultOData<IdentityDbContext>();

#if DEBUG
mvcBuilder.AddRazorRuntimeCompilation();
#endif

services.AddDefaultServices(appSetting);
services.AddIdentityDataService();
services.AddDefaultIdentity();
services.AddTransient<AuthorizationService>();
services.AddTransient<AuthenticationService>();
services.AddDataProtection(appSetting.DataProtection);
services.AddSmsCaptchaService(appSetting.Sms, appSetting.SmsCaptcha);
services.AddWeixinService(appSetting.WeixinApp);
services.AddWeixinService(appSetting.MiniProgram);
services.AddTransient<PhoneNumberCaptchaService>();

builder.AddDefaultIdentityServer(appSetting);
services.AddIdentityAuthentication(appSetting);

var app = builder.Build();
app.UseDefaultBuilder(appSetting, () => app.UseIdentityServer());
await app.Services.GetRequiredService<IMessageCommunicator>().StartAsync();
app.Run();